home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11961 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: ratty.wolfe.net!usenet
  2. From: jrandom@wolfenet.com (Erik Seaberg)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: References & Pointers in Borland C++
  5. Date: Sat, 16 Mar 1996 12:27:38 GMT
  6. Organization: Wolfe Internet Access, L.L.C.
  7. Message-ID: <314aabda.3771725@news1.wolfe.net>
  8. References: <4i26j5$roe@dfw-ixnews3.ix.netcom.com> <4i5aem$9e7@coranto.ucs.mun.ca>
  9. NNTP-Posting-Host: sea-ts1-p37.wolfenet.com
  10. X-Newsreader: Forte Agent .99d/32.182
  11.  
  12. On Wed, 13 Mar 1996 02:04:15 GMT, Steve Austin
  13. <saustin@terra.nlnet.nf.ca> wrote:
  14.  
  15. > [...] given "int &ir = i", by itself "&ir" is *not* an int.
  16.  
  17. I've heard this called "declaration mimics use," and it's unfortunate
  18. that references violate it, but since references are used
  19. transparently, there's no natural operator to hang off the identifier
  20. to declare a reference.  Maybe the syntax should have been
  21.     int *&ir;
  22. which is sort of a "use" that does the right thing to a reference,
  23. though it may overemphasize the theory that a reference is just a
  24. dereferenced pointer (it isn't, necessarily - a compiler has every
  25. right to use a register as the content of a reference, if it can do
  26. the bookkeeping to have everything modify it in-place).
  27.  
  28. > Better I think to avoid this stylistic quirk and write "int* px"
  29. > meaning "px" is a pointer to an integer, and "int& ir = i", meaning
  30. > "ir" is a reference to an integer.
  31.  
  32. Butting the operator symbol up with the type name seems to lead the
  33. unwary to think it's associated with it.  I prefer
  34.     int *a, b;
  35. to
  36.     int* a, b;
  37. since they both declare one pointer and one int, but the unwary might
  38. think the latter declares two pointers.  I know the usual answer is to
  39. declare only one object at a time, but I'm disturbed by the idea of
  40. avoiding legal syntax because I choose a style that makes it
  41. misleading.
  42.